package view;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;
import view.viewPanels.ActGamesViewPanel;
import view.viewPanels.ArchGamesViewPanel;

/**
 * JPanel that displays the beaten figures
 */
@SuppressWarnings( "serial" )
public class FiguresPanel extends JPanel {

    /**
     * the JPanel which contains this figure panel
     */
    private JPanel container;

    /**
     * the color of beaten figures to draw
     */
    private int color;

    /**
     * the size of a field
     */
    private int fieldsize;

    /**
     * constructor of the FiguresPanel
     * 
     * @param container
     *            the JPanel which contains this figure panel
     * @param color
     *            the color of the beaten figures which will be shown in this panel
     */
    public FiguresPanel( JPanel container, int color )
    {
	super();
	this.container = container;
	this.color = color;
	this.fieldsize = 0;
    }

    /**
     * overridden paintComponent from JComponent
     * 
     * @param g
     *            the Graphics object to draw on
     */
    @Override
    public final void paintComponent( Graphics g )
    {
	super.paintComponent( g );
	g.setColor( Color.black );
	if ( this.fieldsize == 0 )
	{
	    this.fieldsize = getSize().height / 8;
	}

	for ( int i = 1; i < 8; i++ )
	{
	    g.drawLine( 0, i * this.fieldsize, this.fieldsize, i * this.fieldsize );
	}

	// draw figures
	if ( this.container == ChessFrame.actGamesViewPanel )
	{
	    ActGamesViewPanel actContainer = (ActGamesViewPanel)this.container;

	    if ( actContainer.getCtActGames().isSelected() )
	    {
		actContainer.getActGamesModel().getActualMatch().repaintFigures( this.fieldsize, g, this.color );
	    }

	}
	else if ( this.container == ChessFrame.archGamesViewPanel )
	{
	    ArchGamesViewPanel archContainer = (ArchGamesViewPanel)this.container;

	    if ( archContainer.getCtArchGames().isSelected() )
	    {
		archContainer.getArchGamesModel().getActualMatch().repaintFigures( this.fieldsize, g, this.color );
	    }

	}

    }

}
